package com.example.demo.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.demo.mapper.UserMapper;
import com.example.demo.model.User;
import com.example.demo.service.UserService;

@RestController
public class GaoxController {
	@Value("${sundyn.name}")
	private String name;
	@Value("${sundyn.title}")
	private String title;
	@Autowired
	private UserService service;
	@Autowired
	private UserMapper userMapper;
	
	
	@RequestMapping("/gaox/add")
	public String add(User user){
		System.out.println(service.insert(user));
		return "success";
	}
	@RequestMapping("/gaox/add2")
	public String add2(User user){
		System.out.println(user.delete(new EntityWrapper<User>().eq("age", 18)));
		return "success";
	}
	
	@RequestMapping("/gaox/demo3.do")
	public String test(HttpServletRequest request) {
		System.out.println(name);
		request.getSession().setAttribute("count", 1);;
		return name;
	}

	@RequestMapping("/gaox/demo4")
	public String test2() {
		return "高兴";
	}
	@RequestMapping("/gaox/test3")
	public void test3(HttpServletRequest request,HttpServletResponse response) {
		try {
			request.getSession().setAttribute("message", "hello ，  baby !");
			request.getSession().setMaxInactiveInterval(60);
//			System.out.println(request.getSession().getMaxInactiveInterval());
			
			request.setCharacterEncoding("utf-8");
			response.setContentType("text/html");
			response.setCharacterEncoding("utf-8");
			response.getWriter().print("测试一下");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
